// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import router from './router'
import fastclick from 'fastclick'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import axios from 'axios'
import VueAxios from 'vue-axios'
import Vuex from 'vuex'
import store from '@/store/store'
import VueLazyLoad from 'vue-lazyload'
import VueCookies from 'vue-cookies'

import 'common/css/iconfont.css'
import 'common/css/sytle.css'
import  'common/css/animate.css'
import 'common/css/swiper.min.css'
Vue.config.productionTip = false;
Vue.use(Vuex);
fastclick.attach(document.body);
Vue.use(VueAxios, axios);
Vue.prototype.$ajax = axios
Vue.use(VueCookies);
Vue.use(VueAwesomeSwiper)

/*进入授权之前的地址*/
Vue.prototype.goBeforeLoginUrl = () => {
  let url = $cookies.get('beforeLoginUrl')
  if (!url || url.indexOf('/authorize') != -1) {
    router.push('/home')
  } else {
    if (url == '/') {
      url = '/home'
    }
    // alert(url)
    router.push(url)
    $cookies.set('beforeLoginUrl', '')
  }
}

/*检查未授权登录跳转至授权页面*/
// router.beforeEach((to, from, next) => {
//   if(!store.state.user && to.path != '/authorize'){
//     // 第一次进入项目
//     $cookies.set('beforeLoginUrl', to.fullPath) // 保存用户进入的url
//     next('/authorize')
//     return false
//   }
//   next()
// })
//
// /*防止已登录的用户进入授权页面*/
// router.beforeEach((to, from, next) => {
//   if(to.path == '/authorize' && store.state.user){
//     next('/home')
//     return false
//   }
//
// })

/*图片懒加载*/
Vue.use(VueLazyLoad,{
  loading:require('common/image/dynamic@2x.png')
})

/*时间戳*/
Vue.filter('time', function (value) {
  return new Date(parseInt(value) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
})

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
